//
//  manyPeopleListenCollectionViewCell.m
//  NewMusic
//
//  Created by dllo on 15/11/12.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "ManyPeopleListenCollectionViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
@interface ManyPeopleListenCollectionViewCell ()
//排序
@property(nonatomic, retain) UILabel *queueLabel;
//图片
@property(nonatomic, retain) UIImageView *picUrlImage;
//名称
@property(nonatomic, retain) UILabel *nameLabel;
//歌手名
@property(nonatomic, retain) UILabel *singerNameLabel;
//心形图片
@property(nonatomic, retain) UIImageView *heartImage;
//喜欢人数
@property(nonatomic, retain) UILabel  *favoritiesLabel;
//播放
@property(nonatomic, retain) UIImageView *showImage;
@end
@implementation ManyPeopleListenCollectionViewCell
- (void)dealloc {
    [_queueLabel release];
    [_picUrlImage release];
    [_nameLabel release];
    [_singerNameLabel release];
    [_heartImage release];
    [_favoritiesLabel release];
    [_showImage release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        //创建视图
        [self createSubView];
    }
    return self;
}
#pragma mark 创建视图
- (void)createSubView {
    //排序
    self.queueLabel = [[UILabel alloc]init];
//    self.queueLabel.backgroundColor = [UIColor redColor];
    self.queueLabel.font = [UIFont fontWithName:@"AmericanTypewriter" size:17];
    self.queueLabel.textAlignment = NSTextAlignmentCenter;
    self.queueLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.queueLabel];
    [self.queueLabel release];
    
    //图片
    self.picUrlImage = [[UIImageView alloc]init];
//    self.picUrlImage.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:self.picUrlImage];
    [self.picUrlImage release];
    
    //歌手名字
    self.singerNameLabel = [[UILabel alloc]init];
//    self.singerNameLabel.backgroundColor = [UIColor yellowColor];
    self.singerNameLabel.textColor = [UIColor colorWithWhite:0.816 alpha:1.000];
    self.singerNameLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.singerNameLabel];
    [self.singerNameLabel release];
    
    //歌名
    self.nameLabel = [[UILabel alloc]init];
//    self.nameLabel.backgroundColor = [UIColor purpleColor];
    self.nameLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel release];
    
    //心形图片
    self.heartImage = [[UIImageView alloc]init];
//    self.heartImage.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.heartImage];
    [self.heartImage release];
    
    //喜欢人数
    self.favoritiesLabel = [[UILabel alloc]init];
//    self.favoritiesLabel.backgroundColor = [UIColor blueColor];
    self.favoritiesLabel.textColor = [UIColor colorWithWhite:0.816 alpha:1.000];
    self.favoritiesLabel.font = [UIFont fontWithName:@"AmericanTypewriter" size:15];
    [self.contentView addSubview:self.favoritiesLabel];
    [self.favoritiesLabel release];
    
    //播放
    self.showImage = [[UIImageView alloc]init];
//    self.showImage.backgroundColor = [UIColor brownColor];
    self.showImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.contentView addSubview:self.showImage];
    [self.showImage release];
}
#pragma mark 设置大小
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    //排行
    self.queueLabel.frame = CGRectMake(0, 5, 30, self.frame.size.height - 10);
    //图片
    self.picUrlImage.frame = CGRectMake(self.queueLabel.frame.size.width + self.queueLabel.frame.origin.x, 0, self.frame.size.width / 5, self.frame.size.height);
    //歌曲名字
    self.nameLabel.frame = CGRectMake(self.picUrlImage.frame.origin.x + self.picUrlImage.frame.size.width + 10, 0, self.frame.size.width / 5 * 2, self.picUrlImage.frame.size.height / 2);
    //歌手名字
    self.singerNameLabel.frame = CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.size.height, self.nameLabel.frame.size.width / 5 * 3, self.nameLabel.frame.size.height);
    //心形图片
    self.heartImage.frame = CGRectMake(self.singerNameLabel.frame.origin.x + self.singerNameLabel.frame.size.width, self.singerNameLabel.frame.origin.y + 10, self.singerNameLabel.frame.size.height - 20, self.singerNameLabel.frame.size.height - 20);
    //喜欢人数
    self.favoritiesLabel.frame = CGRectMake(self.heartImage.frame.origin.x + self.heartImage.frame.size.width + 5, self.heartImage.frame.origin.y, self.nameLabel.frame.size.width - self.singerNameLabel.frame.size.width - self.heartImage.frame.size.width + 20, self.heartImage.frame.size.height);
    //播放图片
    self.showImage.frame = CGRectMake(self.frame.size.width - self.frame.size.width / 6, (self.picUrlImage.frame.size.width - self.frame.size.width / 12) / 2, self.frame.size.width / 12, self.frame.size.width / 12);
}
#pragma mark 重写queueString的setter方法
- (void)setQueueString:(NSString *)queueString {
    if (_queueString != queueString) {
        [_queueString release];
        _queueString = [queueString retain];
    }
    //排行
    self.queueLabel.text = queueString;
}
#pragma mark 重写dataSongsModel的setter方法
- (void)setDataSongsModel:(ListenDataSongsModel *)dataSongsModel {
    if (_dataSongsModel != dataSongsModel) {
        [_dataSongsModel release];
        _dataSongsModel = [dataSongsModel retain];
    }
    //图片
    [self.picUrlImage sd_setImageWithURL:[NSURL URLWithString:dataSongsModel.picUrl]];
    //歌曲名字
    self.nameLabel.text = dataSongsModel.name;
    //歌手名字
    self.singerNameLabel.text = dataSongsModel.singerName;
    //心形图片
    self.heartImage.image = [UIImage imageNamed:@"icon_dianzan"];
    //喜欢人数
    if (dataSongsModel.favorites.length < 4) {
        self.favoritiesLabel.text = dataSongsModel.favorites;
    }else {
    CGFloat number = [[NSString stringWithFormat:@"%.1f万", [dataSongsModel.favorites floatValue] / 10000] floatValue];
    NSNumber *num = [NSNumber numberWithFloat:number];
    self.favoritiesLabel.text = [NSString stringWithFormat:@"%@万", num];
    }
    //播放图片
    self.showImage.image = [UIImage imageNamed:@"icon_bofang"];
}
#pragma mark 重写textColor的setter方法
- (void)setTextColor:(UIColor *)textColor {
    if (_textColor != textColor) {
        [_textColor release];
        _textColor = [textColor retain];
    }
    self.queueLabel.textColor = textColor;
}
@end
